import os
import pathlib
import sys
root_path = str(pathlib.Path(os.path.abspath(__file__)).parent.parent.parent)
sys.path.append(root_path)

from sklearn.ensemble import GradientBoostingClassifier
from ml_utils.config.base_config import *
from ml_utils.model.grid_search import grid_search_cls


def model(x, y, params):
    best_params = grid_search_cls(x, y, GradientBoostingClassifier(), params)
    learning_rate = best_params['learning_rate']
    subsample = best_params['subsample']
    max_depth = best_params['max_depth']
    n_estimators = best_params['n_estimators']
    cls = GradientBoostingClassifier(learning_rate=learning_rate,
                                     subsample=subsample,
                                     max_depth=max_depth,
                                     n_estimators=n_estimators,
                                     random_state=random_state)
    return cls
